﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FTchina;
using System.Collections;

public partial class UI_Callin_Log : System.Web.UI.Page
{

    string deletesql = "delete from Callin_Log where id in ({0}) ";
    string AlertMessage = "编号{0}的项操作{1}";//操作结果提示信息

    protected void Page_Load(object sender, EventArgs e)
    {
        FTchina.basic.CheckAdmin(this);
        FTchina.basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());

        string ids = FTchina.basic.SafeRequest(Request["ids"]);
        string op = FTchina.basic.SafeRequest(Request["op"]);

        if (ids.Length == 0) { GoBack(); }
        if (op.Length == 0) { GoBack(); }

        MainDo(ids, op);
        GoBack();
    }

    /// <summary>
    /// 返回上一页
    /// </summary>
    protected void GoBack()
    {
        string back = FTchina.basic.SafeRequest(Request["back"]);
        if (back.Length > 0)
        {
            JS.JavaScriptLocationHref(back);
        }
        else
        {
            JS.GoHistory(-1);
        }
    }
    protected void MainDo(string ids, string op)
    {
        ArrayList al = new ArrayList();//操作结果的提示集合
        if (ids.Contains(","))
        {
            string[] idsList = ids.Split(',');
            foreach (string str in idsList)
            {
                if (str.Trim().Length > 0)
                {
                    al.Add(ExecList(str, op));
                }
            }
        }
        else
        {
            al.Add(ExecList(ids, op));
        }


        //将操作结果alert出来
        string tmp = string.Empty;
        foreach (string str in al)
        {
            tmp += str + "\\n";//弹出信息换行
        }
        //  tmp = tmp.Substring(0, tmp.Length - 2);
        // LogNet.LogBLL.debug(tmp);
        JS.Alert(tmp);
    }

    /// <summary>
    /// 执行结果的集合
    /// </summary>
    /// <param name="ids"></param>
    /// <param name="tb"></param>
    /// <param name="op"></param>
    /// <returns></returns>
    protected String ExecList(string ids, string op)
    {
        string tmp = string.Empty;


        if (ExecOpSqlSingleByID(ids, op))
        {
            tmp = string.Format(AlertMessage, ids, "成功！");
        }
        else
        {
            tmp = string.Format(AlertMessage, ids, "失败！");
        }
        return tmp;
    }


    /// <summary>
    /// 执行单个操作命令
    /// </summary>
    /// <param name="ids"></param>
    /// <param name="tb"></param>
    /// <param name="op"></param>
    /// <returns></returns>
    protected Boolean ExecOpSqlSingleByID(string ids, string op)
    {
        return ExecSqls(MakeSqls(ids, op));
    }

    /// <summary>
    /// 得到sql语句
    /// </summary>
    /// <param name="ids"></param>
    /// <param name="tb"></param>
    /// <param name="op"></param>
    /// <returns></returns>
    protected string MakeSqls(string ids, string op)
    {
        string tmp = string.Empty;


        switch (op)
        {
            case "del":
                {//删除来电记录
                    tmp = string.Format(deletesql, ids);
                    break;
                }


            default:
                {
                    
                    break;
                }
        }
        //  LogNet.LogBLL.debug(tmp);
        return tmp;
    }
    /// <summary>
    /// 执行sql语句
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    protected Boolean ExecSqls(string sql)
    {
        if (sql.Length > 0)
        {
            //LogNet.LogBLL.info(sql);
            //return true;
            return shujuku.ExecuteSql(sql);
        }
        else
        {
            return false;
        }
    }

}